package cn.scut.user.pojo;

import cn.scut.user.utils.LEVEL;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("user")
public class User {
    @TableId
    private String openid;
    private String username;
    private int level;
    private long experience;

    public void updateLevel() {
        switch (level) {
            case 0:
                if (experience >= LEVEL.LEVEL_LINE_1) {
                    experience -= LEVEL.LEVEL_LINE_1;
                    level++;
                }
                break;
            case 1:
                if (experience >= LEVEL.LEVEL_LINE_2) {
                    experience -= LEVEL.LEVEL_LINE_2;
                    level++;
                }
                break;
            case 2:
                if (experience >= LEVEL.LEVEL_LINE_3) {
                    experience -= LEVEL.LEVEL_LINE_3;
                    level++;
                }
                break;
            case 3:
                if (experience >= LEVEL.LEVEL_LINE_4) {
                    experience -= LEVEL.LEVEL_LINE_4;
                    level++;
                }
                break;
            case 4:
                if (experience >= LEVEL.LEVEL_LINE_5) {
                    experience -= LEVEL.LEVEL_LINE_5;
                    level++;
                }
                break;
            default:
                break;
        }
    }
}
